/**
 * 
 */
(function($) {
	$(document).ready(function() {
		$("#action").click(function() {
			$.ajax({
				type : 'POST',
				url : '/dosearch',
				dataType : 'json',
				data : {
					'keyword' : $('#keywords').val()
				},
				success : function(data) {
					var result = $('#result-panels');
					if (data.length == 0) {
						result.html('<h3>no result ....</h3>');
						return;
					}
					result.html('');
					$.each(data, function (id, item) {
						var desc = $('<div class="panel-body"></div>');
						var header = $('<div class="panel-heading"></div>');
						var panel = $('<div class="panel panel-default"></div>');

						header.append(item.keywords);
						desc.append(item.description);
						panel.append(header).append(desc);

						result.append(panel);
					});
				},
			});
		});

		$('body').keydown(function(event) {
			if (event.keyCode == '13') {
				$("#action").click();
			}
		});
	});
})(jQuery);